package edu.unika.aifb.graphindex.importer.db.metadata;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ForeignKeyConstraint implements Serializable {
	private static final long serialVersionUID = 1695824191179748544L;
	
	private String name;
	private List<Column> sourceColumns;
	private List<Column> targetColumns;
	
	public ForeignKeyConstraint(String name, List<Column> sourceColumns, List<Column> targetColumns){
		this.name = name;
		this.sourceColumns = sourceColumns;
		this.targetColumns = targetColumns;
	}
	
	public ForeignKeyConstraint(String name, Column sourceColumn, Column targetColumn){
		this.name = name;
		this.sourceColumns = new ArrayList<Column>();
		this.targetColumns = new ArrayList<Column>();
		sourceColumns.add(sourceColumn);
		targetColumns.add(targetColumn);
	}

	public String getName() {
		return name;
	}

	public List<Column> getSourceColumns() {
		return sourceColumns;
	}

	public List<Column> getTargetColumns() {
		return targetColumns;
	}
	
	public void addColumnReference(Column sourceColumn, Column targetColumn){
		if(!sourceColumns.contains(sourceColumn) && !targetColumns.contains(targetColumn)){
			sourceColumns.add(sourceColumn);
			targetColumns.add(targetColumn);
		}
	}
}
